/*
 * Copyright (c) 2011 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.snj.visangedu.listeningmax;

import android.view.View;

/**
 * @author gg@google.com (Your Name Here)
 *
 */
public class MP_FileInfo implements Comparable<MP_FileInfo> {
  public int snID;
  public View view;

  public int parentID;

  public String szFullPath;
  public String szPath;
  public String szName; // for server work ..

  public String szExt;

  public boolean bIsFile;

  public boolean bNeedUpdate;
  public boolean bOpenFolder;
  public int iStatus;

  MP_FileInfo(String szFPath, boolean isFileMode) {
    snID = ListeningmaxFragment.iSerialID;
    ListeningmaxFragment.iSerialID++;

    bNeedUpdate = false;
    parentID = 0;
    iStatus = 0;
    bOpenFolder = false;

    SetInfo(szFPath, isFileMode);
  }

  MP_FileInfo(MP_FileInfo info) {
    snID = ListeningmaxFragment.iSerialID;
    ListeningmaxFragment.iSerialID++;

    Copy(info);
  }

  @Override
  public String toString() {
    return szFullPath;
  }

  public int compareTo(MP_FileInfo other) {
    return szFullPath.compareTo(other.szFullPath);
  }

  public void Copy(MP_FileInfo info) {
    szFullPath = info.szFullPath;
    szPath = info.szPath;
    szName = info.szName;
    szExt = info.szExt;
    bIsFile = info.bIsFile;

    parentID = info.parentID;
    bNeedUpdate = info.bNeedUpdate;
    iStatus = info.iStatus;
    bOpenFolder = info.bOpenFolder;
  }

  public void CopyAll(MP_FileInfo info) {
    Copy(info);
    snID = info.snID;
    view = info.view;
  }

  public void SetInfo(String szFPath, boolean isFileMode) {
    szFullPath = szFPath;
    bIsFile = isFileMode;
    szPath = "";
    szName = "";
    szExt = "";

    int pos = szFPath.lastIndexOf('/');
    if (pos == -1) return;

    szPath = szFPath.substring(0, pos);
    String filename = "";

    if ((pos + 1) < szFPath.length()) filename = szFPath.substring(pos + 1);

    if (isFileMode) {
      pos = filename.lastIndexOf('.');
      if (pos > -1) {
        szName = filename.substring(0, pos);
        szExt = filename.substring(pos + 1);
      }
    } else {
      szName = filename;
      szExt = "";
    }
  }


}
